/*     */ package com.zimbra.cs.index;
/*     */ 
/*     */ import com.google.common.collect.Sets;
/*     */ import com.google.common.io.Closeables;
/*     */ import java.io.IOException;
/*     */ import java.util.Collection;
/*     */ import java.util.Iterator;
/*     */ import java.util.Set;
/*     */ import org.apache.lucene.index.IndexReader;
/*     */ import org.apache.lucene.index.Term;
/*     */ import org.apache.lucene.index.TermDocs;
/*     */ import org.apache.lucene.search.DocIdSet;
/*     */ import org.apache.lucene.search.Filter;
/*     */ import org.apache.lucene.util.OpenBitSet;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TermsFilter
/*     */   extends Filter
/*     */ {
/*     */   private static final long serialVersionUID = 3705108370140268162L;
/*  63 */   private final Set<Term> terms = Sets.newTreeSet();
/*     */   
/*     */ 
/*     */ 
/*     */   public TermsFilter(Collection<Term> terms)
/*     */   {
/*  69 */     this.terms.addAll(terms);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public DocIdSet getDocIdSet(IndexReader reader)
/*     */     throws IOException
/*     */   {
/*  77 */     OpenBitSet result = new OpenBitSet(reader.maxDoc());
/*  78 */     TermDocs td = reader.termDocs();
/*     */     try {
/*  80 */       for (iter = this.terms.iterator(); iter.hasNext();) {
/*  81 */         Term term = (Term)iter.next();
/*  82 */         td.seek(term);
/*  83 */         while (td.next())
/*  84 */           result.set(td.doc());
/*     */       }
/*     */     } finally {
/*     */       Iterator<Term> iter;
/*  88 */       Closeables.closeQuietly(td);
/*     */     }
/*  90 */     return result;
/*     */   }
/*     */   
/*     */   public boolean equals(Object obj)
/*     */   {
/*  95 */     if (this == obj) {
/*  96 */       return true;
/*     */     }
/*  98 */     if ((obj == null) || (obj.getClass() != getClass())) {
/*  99 */       return false;
/*     */     }
/* 101 */     TermsFilter test = (TermsFilter)obj;
/* 102 */     return (this.terms == test.terms) || ((this.terms != null) && (this.terms.equals(test.terms)));
/*     */   }
/*     */   
/*     */   public int hashCode()
/*     */   {
/* 107 */     int hash = 9;
/* 108 */     for (Iterator<Term> iter = this.terms.iterator(); iter.hasNext();) {
/* 109 */       Term term = (Term)iter.next();
/* 110 */       hash = 31 * hash + term.hashCode();
/*     */     }
/* 112 */     return hash;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/index/TermsFilter.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */